<template>
  <!-- 登录后所有页面的构建的基础 包含路由导航等 -->
  <v-app style="background: white;">
    <div class="header-wrapper">
      <com-header />
    </div>

    <div style="min-height: 42rem;" id="scrolling-techniques" class="scroll-y">
      <ui-view />
    </div>

    <div class="footer-wrapper flex-center">
      <com-footer />
    </div>

    <!-- <div class="progress-container" v-if="showProgress">
      <div class="progress elevation-2" @click="showProgress = false">
        <v-progress-circular :size="70" :width="5" color="white" indeterminate></v-progress-circular>
        <div class="white--text">{{ progressText }}</div>
      </div>
    </div>

    <v-snackbar v-model="snackbar" :timeout="timeout" top >
      {{ snackbarText }}
      <v-btn color="pink" flat round @click="snackbar = false">
        {{ $t('base.close') }}
      </v-btn>
    </v-snackbar>-->
  </v-app>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { Login } from '@/api';
// import { mapActions } from 'vuex';
import Cookie from 'js-cookie';
import { Action, Mutation, Getter, namespace } from 'vuex-class';
const userModule = namespace('userModule');
declare const $Vue: Vue;


@Component
export default class Home extends Vue {

  @userModule.Action('saveLoginStateFN') saveLoginStateFN: any;
  @userModule.Action('saveUserInfoFN') saveUserInfoFN: any;


  private title: string = "Home";
  private drawer: boolean = true;

  private userInfo: any = {
    balance: 0,
  };



  protected mounted() {
    this.registerTitle();
    // this.registerBalance();
    this.checkLoginStatus();
    this.getUserInfo();
  }

  private checkLoginStatus() {
    let token = Cookie.get('p_token');
    let username = Cookie.get('p_username');
    let userId = Number(Cookie.get('p_userId'));
    let userType = Number(Cookie.get('p_userType'));

    if (token) {
      this.saveUserInfoFN({
        token,
        username,
        userId,
        userType,
      });
      this.saveLoginStateFN(true);
    }
  }

  // 注册加载进度
  private registerTitle() {
    const $this = this;
    $Vue.$on("title", (data: { message: string }) => {
      $this.title = data.message;
    });
  }

  // 注册余额显示
  private registerBalance() {
    const $this = this;
    $Vue.$on("balance", (data: any) => {
      this.getUserInfo();
    });
  }

  /**
   * 获取用户信息
   */
  private async getUserInfo() {

  }

  /**
   * 处理用户注销
   */
  private async handleLogout() {
    const params: any = {
      ticket: Cookie.get('p_token'),
    };
    const { data } = await Login.handleLogout.r(params);
    console.log('handleLogout', data);
    if (data.result === 0) {
    } else {
      $Vue.$emit('snackbar', {
        message: data.message,
      });
    }
  }
}
</script>


<style lang="less" scoped>
.logout {
  background: white;
  padding: 1rem;
  cursor: pointer;
}

.header-wrapper {
  width: 100%;
  height: 10rem;
}

.footer-wrapper {
  width: 100%;
  height: 8rem;
}
</style>

